import java.io.*;

/**
 * The type Net java resp msg.
 */
public class NetJavaRespMsg {

    private int totalLen;

    private int repId;  //回复对应接收到的消息ID

    private byte state=0; //状态 0：正确接收          其它：错误

    private long resTime; //应答方的发送时间

    /**
     * Instantiates a new Net java resp msg.
     *
     * @param repId   the rep id
     * @param state   the state
     * @param resTime the res time
     */
    public NetJavaRespMsg(int repId,byte state,long resTime){

        this.repId=repId;

        this.state=state;

        this.resTime=resTime;

        totalLen=4+4+1+8;

    }

    /**
     * Instantiates a new Net java resp msg.
     *
     * @param udpData the udp data
     */
    public NetJavaRespMsg(byte[] udpData){

        try{

            ByteArrayInputStream bins=new ByteArrayInputStream(udpData);

            DataInputStream dins=new DataInputStream(bins);

            this.totalLen=dins.readInt();

            this.repId=dins.readInt();

            this.state=dins.readByte();

            this.resTime=dins.readLong();

        }catch(Exception e){

            e.printStackTrace();

        }

    }

    /**
     * To byte byte [ ].
     *
     * @return the byte [ ]
     */
    public byte[] toByte(){

        try{

            ByteArrayOutputStream bous=new ByteArrayOutputStream();

            DataOutputStream dous=new DataOutputStream(bous);

            dous.writeInt(this.totalLen);

            dous.writeInt(this.repId);

            dous.writeByte(this.state);

            dous.writeLong(this.resTime);

            dous.flush();

            return bous.toByteArray();

        }catch(Exception e){

            e.printStackTrace();

        }

        return null;

    }

    @Override

    public String toString() {

// TODO Auto-generated method stub

        return "totalLen:"+this.totalLen+"  respID"+this.repId+"  state"+this.state+"  resTime"+resTime;

    }

    /**
     * Gets total len.
     *
     * @return the total len
     */
    public int getTotalLen() {

        return totalLen;

    }

    /**
     * Sets total len.
     *
     * @param totalLen the total len
     */
    public void setTotalLen(int totalLen) {

        this.totalLen = totalLen;

    }

    /**
     * Gets rep id.
     *
     * @return the rep id
     */
    public int getRepId() {

        return repId;

    }

    /**
     * Sets rep id.
     *
     * @param repId the rep id
     */
    public void setRepId(int repId) {

        this.repId = repId;

    }

    /**
     * Gets state.
     *
     * @return the state
     */
    public byte getState() {

        return state;

    }

    /**
     * Sets state.
     *
     * @param state the state
     */
    public void setState(byte state) {

        this.state = state;

    }

    /**
     * Gets res time.
     *
     * @return the res time
     */
    public long getResTime() {

        return resTime;

    }

    /**
     * Sets res time.
     *
     * @param resTime the res time
     */
    public void setResTime(long resTime) {

        this.resTime = resTime;

    }

}